package souket;

import ooday05.StaticMethod;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client {
    private Socket socket;
    public static int a;

    public Client(){
        try {
            System.out.println("正在连接服务器。。。");
            socket =new Socket("localhost",8088);//176.55.8.75 localhost
            System.out.println("与服务器连接成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void start(){
        try {
            OutputStream out=socket.getOutputStream();
            OutputStreamWriter osw=new OutputStreamWriter(out, StandardCharsets.UTF_8);
            BufferedWriter bw=new BufferedWriter(osw);
            PrintWriter pw=new PrintWriter(bw,true);
            pw.println("你好服务器");
            System.out.println("单独输入exit退出输入");
            Scanner sc=new Scanner(System.in);
            while(true){
                String s=sc.nextLine();
                pw.println(s);
                if("exit".equals(s)){break;}
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        Client client=new Client();
        client.start();
    }

}
